/**
 @file ctc_asw_packet.h

 @author  Copyright (C) 2020 Centec Networks Inc.  All rights reserved.

 @date 2020-06-15

 @version v1.0

\p
DMA represent Direct Memory Access. For The Module Asic have 1 Dma Controllers, which perform data transmission between
chip ram and system memory. Dma controller can only use physical address, but CPU using virtual address, So before DMA module init
DAL module must provide several interfaces below:
\b
\d dma_alloc: Alloc Dma memory
\d dma_free: Free Dma memory
\d dal_logic_to_phy: Convert logic address to physical address
\d dal_phy_to_logic: Convert physical address to logic address

\p
\b
DMA module is resource module in SDK, it provides methods for other module using. DMA can provide several functions below:
\d Packet receive and transmit
*/
#ifndef _CTC_ASW_DMA_H
#define _CTC_ASW_DMA_H
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************
*
* Header Files
*
****************************************************************************/
#include "ctc_packet.h"
/***************************************************************************
*
* Defines and Macros
*
****************************************************************************/

/***************************************************************************
*
* Data Structures
*
****************************************************************************/
#if (HOST_IS_LE == 1)
struct ing_ptag_data_s
{
    /*word0[31:0]*/
    uint32 port_bitmap_l                        : 17;
    uint32 port_mode                            : 2;
    uint32 bypass_inacl                         : 1;
    uint32 bypass_inspmac                       : 1;
    uint32 bypass_learning                      : 1;
    uint32 bypass_invlan                        : 1;
    uint32 bypass_instp                         : 1;
    uint32 bypass_inloopback                    : 1;
    uint32 bypass_inprotect                     : 1;
    uint32 bypass_inmeter                       : 1;
    uint32 bypass_eap                           : 1;
    uint32 bypass_isvid                         : 1;
    uint32 bypass_egacl                         : 1;
    uint32 reserved2                            : 2;
    /*word1[31:0]*/
    uint32 bypass_egvlan                        : 1;
    uint32 bypass_egstp                         : 1;
    uint32 bypass_egloopback                    : 1;
    uint32 reserved1                            : 1;
    uint32 bypass_egmeter                       : 1;
    uint32 reserved0                            : 1;
    uint32 bitmap_mode                          : 1;
    uint32 fid                                  : 12;
    uint32 qpdp                                 : 6;
    uint32 use_this_qpdp                        : 1;
    uint32 not_modify                           : 1;
    uint32 cnt_index_10_4_0                     : 5;
    /*word2[31:0]*/
    uint32 cnt_index_10_9_5                     : 5;
    uint32 cnt_mode                             : 2;
    uint32 cnt_addtail                          : 2;
    uint32 cnt_insert                           : 3;
    uint32 tscnt_offset                         : 8;
    uint32 ts_mode                              : 2;
    uint32 ts_addtail                           : 2;
    uint32 ts_1588cf                            : 2;
    uint32 ts_insert                            : 3;
    uint32 oam_port_based                       : 1;
    uint32 oam_y1564                            : 1;
    uint32 is_inservice                         : 1;
    /*word3[15:0]*/
    uint16 inservice_meter_mode                 : 1;
    uint32 inservice_meter_dir                  : 1;
    uint32 inservice_meter_id                   : 11;
    uint32 opcode                               : 3;
    uint32 ptag_tpid                            : 16;
};

struct eg_ptag_data_s
{
    /*word0[31:0]*/
    uint32 vlan_num                             : 3;
    uint32 layer_type                           : 3;
    uint32 ip_type                              : 2;
    uint32 oam_1588_type                        : 2;
    uint32 itag_action                          : 2;
    uint32 otag_action                          : 2;
    uint32 itag_status                          : 2;
    uint32 tail_cnt                             : 1;
    uint32 tail_ts                              : 1;
    uint32 ts_mode                              : 2;
    uint32 acl_index                            : 8;
    uint32 acl_index_vld                        : 1;
    uint32 spmac_index_vld                      : 1;
    uint32 src_port_6_1_0                       : 2;
    /*word1[31:0]*/
    uint32 src_port_6_5_2                       : 4;
    uint32 arl_cpucopy                          : 4;
    uint32 oam_ptag_tocpu                       : 1;
    uint32 cpu_ptag_tocpu                       : 1;
    uint32 oam_tocpu                            : 2;
    uint32 ptp_tocpu                            : 1;
    uint32 smac_tocpu                           : 1;
    uint32 pmac_tocpu                           : 1;
    uint32 acl_tocpu                            : 1;
    uint32 ingmir_tocpu                         : 1;
    uint32 egmir_tocpu                          : 1;
    uint32 ip_have_option                       : 1;
    uint32 ivt_unknown_tocpu                    : 1;
    uint32 ivt_chk_fail_tocpu                   : 1;
    uint32 not_learning                         : 1;
    uint32 qp                                   : 3;
    uint32 local_pri                            : 4;
    uint32 local_color                          : 2;
    uint32 internal_svid_12_0_0                 : 1;
    /*word2[31:0]*/
    uint32 internal_svid_12_11_1                : 11;
    uint32 dport_bitmap_26_20_0                 : 21;
    /*word3[15:0]*/
    uint32 dport_bitmap_26_25_21                : 5;
    uint32 cnt_index                            : 10;
    uint32 reserved0                            : 1;
    uint32 ptag_tpid                            : 16;
};
#else
struct ing_ptag_data_s
{
    /*word0[31:0]*/
    uint32 reserved2                            : 2;
    uint32 bypass_egacl                         : 1;
    uint32 bypass_isvid                         : 1;
    uint32 bypass_eap                           : 1;
    uint32 bypass_inmeter                       : 1;
    uint32 bypass_inprotect                     : 1;
    uint32 bypass_inloopback                    : 1;
    uint32 bypass_instp                         : 1;
    uint32 bypass_invlan                        : 1;
    uint32 bypass_learning                      : 1;
    uint32 bypass_inspmac                       : 1;
    uint32 bypass_inacl                         : 1;
    uint32 port_mode                            : 2;
    uint32 port_bitmap_l                        : 17;
    /*word1[31:0]*/
    uint32 cnt_index_10_4_0                     : 5;
    uint32 not_modify                           : 1;
    uint32 use_this_qpdp                        : 1;
    uint32 qpdp                                 : 6;
    uint32 fid                                  : 12;
    uint32 bitmap_mode                          : 1;
    uint32 reserved0                            : 1;
    uint32 bypass_egmeter                       : 1;
    uint32 reserved1                            : 1;
    uint32 bypass_egloopback                    : 1;
    uint32 bypass_egstp                         : 1;
    uint32 bypass_egvlan                        : 1;
    /*word2[31:0]*/
    uint32 is_inservice                         : 1;
    uint32 oam_y1564                            : 1;
    uint32 oam_port_based                       : 1;
    uint32 ts_insert                            : 3;
    uint32 ts_1588cf                            : 2;
    uint32 ts_addtail                           : 2;
    uint32 ts_mode                              : 2;
    uint32 tscnt_offset                         : 8;
    uint32 cnt_insert                           : 3;
    uint32 cnt_addtail                          : 2;
    uint32 cnt_mode                             : 2;
    uint32 cnt_index_10_9_5                     : 5;
    /*word3[15:0]*/
    uint32 ptag_tpid                            : 16;
    uint32 opcode                               : 3;
    uint32 inservice_meter_id                   : 11;
    uint32 inservice_meter_dir                  : 1;
    uint32 inservice_meter_mode                 : 1;
};

struct eg_ptag_data_s
{
    /*word0[31:0]*/
    uint32 src_port_6_1_0                       : 2;
    uint32 spmac_index_vld                      : 1;
    uint32 acl_index_vld                        : 1;
    uint32 acl_index                            : 8;
    uint32 ts_mode                              : 2;
    uint32 tail_ts                              : 1;
    uint32 tail_cnt                             : 1;
    uint32 itag_status                          : 2;
    uint32 otag_action                          : 2;
    uint32 itag_action                          : 2;
    uint32 oam_1588_type                        : 2;
    uint32 ip_type                              : 2;
    uint32 layer_type                           : 3;
    uint32 vlan_num                             : 3;
    /*word1[31:0]*/
    uint32 internal_svid_12_0_0                 : 1;
    uint32 local_color                          : 2;
    uint32 local_pri                            : 4;
    uint32 qp                                   : 3;
    uint32 not_learning                         : 1;
    uint32 ivt_chk_fail_tocpu                   : 1;
    uint32 ivt_unknown_tocpu                    : 1;
    uint32 ip_have_option                       : 1;
    uint32 egmir_tocpu                          : 1;
    uint32 ingmir_tocpu                         : 1;
    uint32 acl_tocpu                            : 1;
    uint32 pmac_tocpu                           : 1;
    uint32 smac_tocpu                           : 1;
    uint32 ptp_tocpu                            : 1;
    uint32 oam_tocpu                            : 2;
    uint32 cpu_ptag_tocpu                       : 1;
    uint32 oam_ptag_tocpu                       : 1;
    uint32 arl_cpucopy                          : 4;
    uint32 src_port_6_5_2                       : 4;
    /*word2[31:0]*/
    uint32 dport_bitmap_26_20_0                 : 21;
    uint32 internal_svid_12_11_1                : 11;
    /*word3[15:0]*/
    uint16 ptag_tpid                            : 16;
    uint16 reserved0                            : 1;
    uint16 cnt_index                            : 10;
    uint16 dport_bitmap_26_25_21                : 5;
};
#endif
typedef struct ing_ptag_data_s ing_ptag_data_t;
typedef struct eg_ptag_data_s eg_ptag_data_t;

/***************************************************************************
*
*  Functions
*
****************************************************************************/
/**
 @defgroup packet
 @{
*/

/**
 @brief Initialize the packet module

 @param[in] lchip    local chip id

 @param[in] p_global_cfg    pointer to packet initialize parameter, refer to ctc_pkt_global_cfg_t

 @remark[TMA]   Packet module init interface

 @return CTC_E_XXX

*/
extern int32
ctc_asw_packet_init(uint8 lchip, void* p_global_cfg);


/**
 @brief De-Initialize packet module

 @param[in] lchip    local chip id

 @remark[TMA]  User can de-initialize the packet configuration

 @return CTC_E_XXX
*/
extern int32
ctc_asw_packet_deinit(uint8 lchip);

/**
 @brief Encapsulate packet header for packet from CPU to Chip

 @param[in] lchip    local chip id

 @param[in|out] p_pkt_tx    pointer to packet TX

 @remark[TMA]  User need to call this API to encapsulate packet header if SDK is in ETH mode.
          SDK will automatically encapsulate packet header if SDK is in DMA mode.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_packet_encap(uint8 lchip, ctc_pkt_tx_t* p_pkt_tx);

/**
 @brief Decapsulate packet header for packet from Chip to CPU

 @param[in] lchip    local chip id

 @param[in|out] p_pkt_rx    pointer to packet RX

 @remark[TMA]  User need to call this API to decapsulate packet header if SDK is in ETH mode.
          SDK will automatically decapsulate packet header if SDK is in DMA mode.

 @return CTC_E_XXX
*/
extern int32
ctc_asw_packet_decap(uint8 lchip, ctc_pkt_rx_t* p_pkt_rx);

/**@} end of @defgroup   */
#ifdef __cplusplus
}
#endif

#endif

